package com.ews.onlineexchange.controller;

import java.util.ArrayList;
import java.util.List;

import javax.enterprise.inject.Model;
import javax.inject.Inject;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.model.QualificationCert;
import com.ews.onlineexchange.model.QualificationLevel;
import com.ews.onlineexchange.model.QualificationTemplate;
import com.ews.onlineexchange.model.ServiceSupplier;
import com.ews.onlineexchange.service.EntityQuery;

@Model
public class SupplierSelectorList extends EntityQuery<ServiceSupplier> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<ServiceSupplier> entity) {
		List<Predicate> restrictions = new ArrayList<Predicate>();
		restrictions.add(cb.equal(entity.get("delFlag"), DataEntity.DEL_FLAG_NORMAL));
		restrictions.add(cb.isTrue(entity.<Boolean>get("valid")));
		restrictions.add(cb.isTrue(entity.<Boolean>get("auditted")));
		Join<ServiceSupplier,QualificationCert> crets = entity.join("certs");
		restrictions.add(cb.isTrue(crets.<Boolean>get("valid")));
		Join<QualificationTemplate, QualificationLevel> level = entity.join("certs").join("qualificationTemplates").join("qualificationLevel");
//		restrictions.add(cb.ge(level.get("value"), y)));
		
		return restrictions;
	}
	
}
